The database was not the main part of the project but is still vital. Designing the database had to be done in a fast and appropriate way so that it could be finished as soon as possible. 

We discussed at early stage what kind of database we could use. Because none of the group members had previous knowledge of database installation we decided to use the Oracle database at the Chalmers university which we had access to it from previous courses. This could be easily changed and transferred to a local database in a later stage if needed.

The ER-diagram in Figure \ref{fig:ER} shows the initial scetch, the entities and the relation between them. The following entities and relations would later become rows and columns in the database tables:
\newpage
\begin{enumerate}
  \item \textbf{Meals}. This would include the meal names and the time required to prepare the meals.
  \item \textbf{Ingredients}. This would include the name of all ingredients required for all the meals in the database.
  \item \textbf{Meal categories}. This would include the type of the meals. Meals would have categories like vegetarian, festive, children, fast and more.
  \item \textbf{Way to cook}. This would include the way too cook the meals.
  \item \textbf{Meal ingredients}. This table describes the relation between the meals and their ingredients. It includes the specific ingredients, amount and unit.
\end{enumerate}

\begin{figure}[!ht]
 \centering
 \includegraphics[scale=0.35]{ER.pdf}
 % ER.pdf: 1179666x1310738 pixel, 0dpi, infxinf cm, bb=
 \caption{The ER-diagram with entities and their releations.}
 \label{fig:ER}
\end{figure}


The ER-diagram was implemented and Figure \ref{fig:database} shows an example of the table \textit{meal ingredients}. A total of 15 meals were inserted in the database. These were collected from the internet recipe database (www.recipesource.com) suggested on the course website. Each meal has several categories.

\begin{figure}[!ht]
 \centering
 \includegraphics[scale=0.47]{database.png}
 % untitled.JPG: 0x0 pixel, 0dpi, nanxnan cm, bb=
 \caption{An example of the database table mealingredeints.}
 \label{fig:database}
\end{figure}


\subsubsection{Database interface}
The interface to the database was implemened using Java DataBase Connectivity (JDBC). Java provides the \verb+Java.sql+ library which include the methods required to connect and search the database. We created a class called Jdbc which sets up the connection to the database.

\subsubsection{Searching the database}

In early stages of the project it was decided that the database would be searched based on a form. This means that a form containing fields of ingredients to include or exclude, meal categories to include or exclude, and specific meal names, will be filled.  Based on these fields queries to the database will be generated. The form was later implemented in a class called QueryForm and the fields were implemented as lists in that class.

For example one method among others is called CheckExcIngr and searches the database for items stored in the exclude-ingredients list in QueryForm. Here is a pseudo code example:

\begin{tabbing}
	for \=(int i = 0; i $<$ excludeIngredients.size(); i++) \{ \\
	\>	Select meal from database where excludeIngredients.get(i) does not exist. \\
	\} \\
\end{tabbing}

The phrase inside the for loop is quite complex because it will have to combine all items in the excludeIngredients list in a query string and at the end send that query to the database.

These methods could later be called anytime and at any point in the program. The query form approach also made it easy for us in a way that we did not have to generate special or unexpected queries. Instead we created about ten queries that could get all the information we needed from the database.
